<template>
  <el-card>
    <el-form inline>
      <el-form-item label="一级分类" label-width="90px">
        <el-select
          v-model="$store.state.category.category1Id"
          placeholder="请选择"
        >
          <el-option
            v-for="c1 in categoryOneList"
            :key="c1.id"
            :label="c1.name"
            :value="c1.id"
            >{{ c1.name }}</el-option
          >
        </el-select>
      </el-form-item>
      <el-form-item label="二级分类" label-width="90px">
        <el-select
          v-model="$store.state.category.category2Id"
          placeholder="请选择"
        >
          <el-option
            v-for="c2 in categoryTwoList"
            :key="c2.id"
            :label="c2.name"
            :value="c2.id"
            >{{ c2.name }}</el-option
          >
        </el-select>
      </el-form-item>
      <el-form-item label="三级分类" label-width="90px">
        <el-select
          v-model="$store.state.category.category3Id"
          placeholder="请选择"
        >
          <el-option
            v-for="c3 in categoryThreeList"
            :key="c3.id"
            :label="c3.name"
            :value="c3.id"
            >{{ c3.name }}</el-option
          >
        </el-select>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script>
import { mapState } from 'vuex'
export default {
  name: 'Attr',
  // props: ['isShowList'],
  data() {
    return {
      form: {
        name: '',
        region: '',
        date1: '',
        date2: '',
        delivery: false,
        type: [],
        resource: '',
        desc: ''
      }
    }
  },
  computed: {
    ...mapState({
      categoryOneList: (state) => state.category.categoryOneList,
      category1Id: (state) => state.category.category1Id,
      categoryTwoList: (state) => state.category.categoryTwoList,
      category2Id: (state) => state.category.category2Id,
      categoryThreeList: (state) => state.category.categoryThreeList,
      category3Id: (state) => state.category.category3Id
    })
  },
  watch: {
    category1Id(newValue, oldValue) {
      this.$store.dispatch('getCategoryTwoList', this.category1Id)
    },
    category2Id(newValue, oldValue) {
      this.$store.dispatch('getCategoryThreeList', this.category2Id)
    }
  },
  mounted() {
    this.getCategoryOneList()
  },

  methods: {
    onSubmit() {},
    getCategoryOneList() {
      this.$store.dispatch('getCategoryOneList')
    }
  }
}
</script>

<style lang="less" scoped>
</style>
